const mongoose=require('mongoose');
const DB_URL='mongodb://localhost:27017/douban-top250'
mongoose.connect(DB_URL)

const models={
  work:{
    'title':{type:String,require:true},
    'pic':{type:String,require:true},
    'director':{type:String,require:true},
    'writer':{type:String,require:true},
    'actor':{type:String,require:true},
    'mType':{type:String,require:true},
    'country':{type:String,require:true},
    'language':{type:String,require:true},
    'show_date':{type:String,require:true},
    'other':{type:String,require:true},
    'imDb':{type:String,require:true},
    'info':{type:String,require:true}
  },
  work_short:{
    'work_id':{type:String,require:true},
    'author':{type:String,require:true},
    'info':{type:String,require:true}
  },
  work_long:{
    'work_id':{type:String,require:true},
    'pic':{type:String,require:true},
    'author':{type:String,require:true},
    'title':{type:String,require:true},
    'info':{type:String,require:true}
  }
}

for(let m in models){
  mongoose.model(m,new mongoose.Schema(models[m]))
}

module.exports={
  getModel:function(name) {
    return mongoose.model(name)
  }
}
